package com.example.kpopnews.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

import com.example.kpopnews.Config;
import com.example.kpopnews.KpopNewsApplication;

//******************************************************************
public final class Utils
// ******************************************************************
{
	/** The small text font size percent of screen height */
	private static final float TEXT_SMALL_SIZE_PERCENT = 2.75f;

	/** The medium text font size percent of screen height */
	private final static float TEXT_MEDIUM_SIZE_PERCENT = 3.05f;

	/** The large text font size percent of screen height */
	private final static float TEXT_LARGE_SIZE_PERCENT = 3.33f;

	private final static int SCREEN_HEIGHT = getScreenHeight();

	private static DisplayMetrics sDisplayMetrics = new DisplayMetrics();

	// ******************************************************************
	static
	// ******************************************************************
	{
		WindowManager windowManager = ((WindowManager) KpopNewsApplication.getInstance().getSystemService(
				Context.WINDOW_SERVICE));
		Display display = windowManager.getDefaultDisplay();
		display.getMetrics(sDisplayMetrics);
	}

	// ******************************************************************
	private Utils()
	// ******************************************************************
	{
	}

	// ******************************************************************
	public static int getScreenWidth()
	// ******************************************************************
	{
		return sDisplayMetrics.widthPixels;
	}

	// ******************************************************************
	public static int getScreenHeight()
	// ******************************************************************
	{
		return sDisplayMetrics.heightPixels;
	}

	// ******************************************************************
	public static float getScreenDensity()
	// ******************************************************************
	{
		return sDisplayMetrics.density;
	}

	/** Get small text font size */
	// ******************************************************************
	public static int getSmallSize()
	// ******************************************************************
	{
		return (int) (SCREEN_HEIGHT * getPercentTextSize(TEXT_SMALL_SIZE_PERCENT) / 100);
	}

	/** Get medium text font size */
	// ******************************************************************
	public static int getMediumSize()
	// ******************************************************************
	{
		return (int) (SCREEN_HEIGHT * getPercentTextSize(TEXT_MEDIUM_SIZE_PERCENT) / 100);
	}

	/** Get large text font size */
	// ******************************************************************
	public static int getLargeSize()
	// ******************************************************************
	{
		return (int) (SCREEN_HEIGHT * getPercentTextSize(TEXT_LARGE_SIZE_PERCENT) / 100);
	}

	/** Increase the text size in small resolution */
	// ******************************************************************
	private static float getPercentTextSize(float defaultPercent)
	// ******************************************************************
	{
		return SCREEN_HEIGHT >= 480 ? defaultPercent : (defaultPercent + 0.5f);
	}

	// ******************************************************************
	public static void debug(String message)
	// ******************************************************************
	{
		if (Config.IS_DEBUG)
		{
			Log.d("Kpopnews", "@@@@@@@@@@@@@@@@@@ " + message);
		}
	}
}
